package com.learnJava;

import java.util.*;

/**
 * Created by Aqc on 2017/7/27.
 */

class mySingleClass {
    private static volatile mySingleClass ms;

    private mySingleClass() {
    }

    public static mySingleClass getMyClass() {
        if (ms == null) {
            synchronized (mySingleClass.class) {
                if (ms == null) {
                    ms = new mySingleClass();
                }
            }
        }
        return ms;
    }
}

public class myHashSet {
    public static void main(String[] args) {
        mySingleClass m1 = mySingleClass.getMyClass();
        mySingleClass m2 = mySingleClass.getMyClass();
        HashSet hs = new HashSet();
        hs.add(m1);
        if (hs.add(m2)) {
            System.out.println("true");
        } else {
            System.out.println("false");
        }
        hs.add("string");
        System.out.println("hs:" + hs);
        System.out.println();

    }
}
